home *** CD-ROM | disk | FTP | other *** search
- /*
-
- SolveRubiksCube
- Copyright (c) 1994 J Robert Boonstra
-
- */
-
- #pragma options(honor_register,assign_registers)
-
- #include "rubik.h"
- #include "transform.h"
-
- /*
- * Moves to transfer a cube to the middle face.
- */
- /* FDDLDlDDf Up face matches Left center */
- #define FDDLDlDDf F1;D2;L1;D1;L3;D2;F3;
-
- #define RDDFDfDDr R1;D2;F1;D1;F3;D2;R3;
-
- #define BDDRDrDDb B1;D2;R1;D1;R3;D2;B3;
-
- #define LDDBDbDDl L1;D2;B1;D1;B3;D2;L3;
-
- Boolean SolveMiddleLayer(register RubiksCube *rub)
- {
- short loopCount;
- loopCount=0;
- /**********************************************************
- *
- * STEP 3: Put the (edge) cubes in the middle layer into
- * the proper position and orientation.
- * Loop until all are correct.
- *
- *********************************************************/
- do {
- if (++loopCount > 24) return false;
- if (DF_F != D && DF_D != D) { /* DF in wrong position*/
- if (DF_F == F && DF_D == R) { D3F1D2L1D1L3D2F3;
- } else if (DF_F == R && DF_D == F) { F1D2L1D1L3D2F3;
- } else if (DF_F == R && DF_D == B) { R1D2F1D1F3D2R3;
- } else if (DF_F == B && DF_D == R) { D1R1D2F1D1F3D2R3;
- } else if (DF_F == B && DF_D == L) { D1B1D2R1D1R3D2B3;
- } else if (DF_F == L && DF_D == B) { D2B1D2R1D1R3D2B3;
- } else if (DF_F == L && DF_D == F) { D2L1D2B1D1B3D2L3;
- } else if (DF_F == F && DF_D == L) { D3L1D2B1D1B3D2L3;
- }
- continue;
- } else if (DR_R != D && DR_D != D) {/* DR in wrong pos*/
- if (DR_R == F && DR_D == R) { D2F1D2L1D1L3D2F3;
- } else if (DR_R == R && DR_D == F) { D3F1D2L1D3L3D2F3;
- } else if (DR_R == R && DR_D == B) { D3R1D2F1D1F3D2R3;
- } else if (DR_R == B && DR_D == R) { R1D2F1D3F3D2R3;
- } else if (DR_R == B && DR_D == L) { B1D2R1D1R3D2B3;
- } else if (DR_R == L && DR_D == B) { D1B1D2R1D3R3D2B3;
- } else if (DR_R == L && DR_D == F) { D1L1D2B1D1B3D2L3;
- } else if (DR_R == F && DR_D == L) { D2L1D2B1D3B3D2L3;
- }
- continue;
- } else if (DB_B != D && DB_D != D) {/* DB in wrong pos*/
- if (DB_B == F && DB_D == R) { D1F1D2L1D1L3D2F3;
- } else if (DB_B == R && DB_D == F) { D2F1D2L1D3L3D2F3;
- } else if (DB_B == R && DB_D == B) { D2R1D2F1D1F3D2R3;
- } else if (DB_B == B && DB_D == R) { D3R1D2F1D3F3D2R3;
- } else if (DB_B == B && DB_D == L) { D3B1D2R1D1R3D2B3;
- } else if (DB_B == L && DB_D == B) { B1D2R1D3R3D2B3;
- } else if (DB_B == L && DB_D == F) { L1D2B1D1B3D2L3;
- } else if (DB_B == F && DB_D == L) { D1L1D2B1D3B3D2L3;
- }
- continue;
- } else if (DL_L != D && DL_D != D) {/* DL in wrong pos*/
- if (DL_L == F && DL_D == R) { F1D2L1D1L3D2F3;
- } else if (DL_L == R && DL_D == F) { D1F1D2L1D3L3D2F3;
- } else if (DL_L == R && DL_D == B) { D1R1D2F1D1F3D2R3;
- } else if (DL_L == B && DL_D == R) { D2R1D2F1D3F3D2R3;
- } else if (DL_L == B && DL_D == L) { D2B1D2R1D1R3D2B3;
- } else if (DL_L == L && DL_D == B) { D3B1D2R1D3R3D2B3;
- } else if (DL_L == L && DL_D == F) { D3L1D2B1D1B3D2L3;
- } else if (DL_L == F && DL_D == L) { L1D2B1D3B3D2L3;
- }
- continue;
- }
- /*
- * Exit if all edge cubes in the middle layer are in the
- * correct position and orientation.
- */
- else if (LF_F == F && RF_F == F &&
- RF_R == R && RB_R == R &&
- LB_B == B && RB_B == B &&
- LF_L == L && LB_L == L) {
- break;
- } else {
- /*
- * All edges are not correct, but there are no edge cubes
- * in the bottom layer that belong in the middle layer.
- * Need to move an incorrectly placed cube from the middle
- * layer into the bottom layer, so that the next loop can
- * orient it correctly.
- */
- if (RF_F != F || RF_R != R) { F1D2L1D1L3D2F3;
- } else if (RB_R != R || RB_B != B) { R1D2F1D1F3D2R3;
- } else if (LB_B != B || LB_L != L) { B1D2R1D1R3D2B3;
- } else if (LF_L != L || LF_F != F) { L1D2B1D1B3D2L3;
- }
- continue;
- }
- } while(true);
- return (true);
- }